﻿//LeftCategoryNavigationOff Begin
$(function () {
    var interval;
    $(".nav_stand2 .nav_tit").mouseover(function () {
        clearTimeout(interval);
        $(".nav_tit").addClass('on');
        $(".dlList").removeClass('no').addClass('on');
    })

    $(".nav_stand2").mouseleave(function () {
        interval = setTimeout(function () {
            $(".dlList").addClass('no').removeClass('on');
            $(".nav_tit").removeClass('on');
        }, 10);
    });
});
//LeftCategoryNavigationOff End

//OnlineCounselingFloat Begin
$(function () {
    if ($.trim($("#onlinecounselingfloat_content").html()) == "") {
        $("#onlinecounselingfloat").hide();
    }
    $("#onlinecounselingfloat_close").click(function () {
        $("#onlinecounselingfloat").hide();
        return false;
    });
    //判断浏览器版本
    var isIE6 = false;
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : 0;
    if (Sys.ie && Sys.ie == "6.0") {
        isIE6 = true;
    }
    if (isIE6) {
        $("#onlinecounselingfloat").css("position", "absolute");
    }
    $(window).scroll(function () {
        if (isIE6) {
            var offsetTop = 140 + $(window).scrollTop() + "px";
            $("#onlinecounselingfloat").animate({ top: offsetTop }, { duration: 600, queue: false });
        }
    });
});
//OnlineCounselingFloat End

//CitySelector Begin
$(function () {
    var actualCityId = $("#city_selector").attr("acid");
    if ((actualCityId == '' || actualCityId == '0')) {
        var top = (document.documentElement.clientHeight - $("#city_selector").height()) / 2;
        $("#city_selector").overlay({ mask: { color: "#aaa" }, load: true, closeOnClick: false, top: top, onClose: function () { $("select").show(); } }).load();
        $("select").hide();
    }

    $(".citySelect").attr("href", location.href);
    $(".citySelect").click(function () {
        var cityId = $(this).attr("cid");
        $.cookie('soukecityid', cityId, { expires: 3650, path: '/', domain: 'xdf.cn' });
        $.cookie('city', cityId, { expires: 3650, path: '/' });
    });
});
//CitySelector End

//SelectCity Begin
$(function () {
    var interval;
    $("#selectcity").mouseover(function () {
        clearTimeout(interval);
        $("#selectcity").addClass('on');
        $("#selectcity_pop").show();
    }).mouseleave(function () {
        interval = setTimeout(function () {
            $("#selectcity_pop").hide();
            $("#selectcity").removeClass('on');
        }, 10);
    });

    $("#selectcity_pop").mouseover(function () {
        clearTimeout(interval);
    }).mouseleave(function () {
        interval = setTimeout(function () {
            $("#selectcity_pop").hide();
            $("#selectcity").removeClass('on');
        }, 10);
    });
    $(".cityChange").click(function () {
        var cityId = $(this).attr("cid");
        $.cookie('soukecityid', cityId, { expires: 3650, path: '/', domain: 'xdf.cn' });
        $.cookie('city', cityId, { expires: 3650, path: '/' });
    });
});
//SelectCity End

//SearchBar Begin
$(function () {
    if ($.trim($("#txtKeyWord").val()) != $("#txtKeyWord").attr('defaultvalue')) {
        $("#txtKeyWord").removeClass('col_gray');
    }
    $("#txtKeyWord").focus(function () {
        if ($.trim($(this).val()) == $(this).attr('defaultvalue')) {
            $(this).val("");
        }
        $(this).removeClass('col_gray');
    });
    $("#txtKeyWord").blur(function () {
        if ($.trim($(this).val()) == "") {
            $(this).val($(this).attr('defaultvalue'));
            $(this).addClass('col_gray');
        }
    });

    $("#txtKeyWord").autocomplete("/Handlers/AutoCompleteHandler.ashx", {
        width: 435,
        dataType: "json",
        matchContains: true,
        extraParams: { "CityId": $("#searchBar").attr('cid') },
        scroll: false,
        parse: function (data) {
            var rows = [];
            for (var i = 0; i < data.length; i++) {
                rows[rows.length] = {
                    data: data[i],
                    value: data[i],
                    result: data[i]
                };
            }
            return rows;
        },
        formatItem: function (row) {
            return "<p>" + row + " </p>";
        },
        formatResult: function (row) {
            return row[0].replace(/(<.+?>)/gi, '');
        },
        confirmSelect: function (select) {
            Search();
            //if (event.keyCode != 13 && event.which != 13) {
                //Search();
            //}
        }
    });

    $("#txtKeyWord").keydown(function (event) {
        if (event.keyCode == 13 || event.which == 13) {
            Search();
        }
    });

    $("#btnSearchBar").click(function () {
        Search();
    });
});

function Search() {
    var keyWord = $.trim($("#txtKeyWord").val());
    if (keyWord != $("#txtKeyWord").attr('defaultvalue') && keyWord != "") {
        window.location = encodeURI("/Search.aspx?cid=" + $("#searchBar").attr('cid') + "&kw=" + keyWord);
    }
    else {
        return false;
    }
}
//SearchBar End

//MiniShoppingCart Begin
$(function () {
    $("#cartProductList dl:nth-child(odd)").addClass("dl_bg");

    var interval;
    $("#viewCartProduct").mouseover(function () {
        clearTimeout(interval);
        $("#viewCartProduct").addClass('mouse_on');
        $("#cartProductList").removeClass('no');
    })

    $(".car").mouseleave(function () {
        interval = setTimeout(function () {
            $("#viewCartProduct").removeClass('mouse_on');
            $("#cartProductList").addClass('no');
        }, 10);
    });
});
//MiniShoppingCart End